package com.scuec.tourismwebsite.service;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.scuec.tourismwebsite.entity.Post;
import com.scuec.tourismwebsite.mapper.PostMapper;
import com.scuec.tourismwebsite.vo.OrderUserBoutique;
import com.scuec.tourismwebsite.vo.UserPost;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Collections;
import java.util.List;

@Service
public class PostServiceImpl implements PostService {
    @Autowired
    private PostMapper postMapper;

    @Override
    public List<UserPost> findPostByNickname(String nickname) {
        return postMapper.findPostByNickname(nickname);
    }

    @Override
    public Integer insertPost(Post post) {
        return postMapper.insertPost(post);
    }

    @Override
    public List<Object[]> findPostByUserId(Integer user_id) {
        return postMapper.findPostByUserId(user_id);
    }

    @Override
    public List<UserPost> findPostAll() {
        return postMapper.findPostAll();
    }

    @Override
    public Integer deletePostById(Integer post_id) {
        return postMapper.deletePostById(post_id);
    }

    @Override
    public UserPost findPostById(Integer post_id) {
        return postMapper.findPostById(post_id);
    }

    @Override
    public List<UserPost> findUserPostByCategory(String category) {
        return  postMapper.findUserPostByCategory(category);
    }

    @Override
    public Integer updatePostCount(Integer post_id, Integer likes_count, Integer comments_count, Integer collect_counts) {
        return postMapper.updatePostCount(post_id, likes_count, comments_count, collect_counts);
    }


    @Override
    public PageInfo<UserPost> findUserPostPages(Integer pageNum, Integer pageSize) {
        PageHelper.startPage(pageNum,pageSize);
        List<UserPost> lists = postMapper.findPostAll();
        PageInfo<UserPost> pageInfo = new PageInfo<>(lists);
        return pageInfo;
    }

    @Override
    public PageInfo<UserPost> findUserPostPage(String nickname, Integer pageNum, Integer pageSize) {
        PageHelper.startPage(pageNum,pageSize);
        List<UserPost> lists =findPostByNickname(nickname);
        PageInfo<UserPost> pageInfo = new PageInfo<>(lists);
        return pageInfo;
    }
}
